﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.IO.IsolatedStorage;
using System.IO;

namespace HGLLCP
{
    public partial class MainPage : PhoneApplicationPage
    {
        // 构造函数
        public MainPage()
        {
            InitializeComponent();

            #region CopyContentToIsolatedStorage

            Common.CopyContentToIsolatedStorage("assets/classlist.txt");
            Common.CopyContentToIsolatedStorage("assets/newslist_152.txt");
            Common.CopyContentToIsolatedStorage("assets/newslist_153.txt");
            Common.CopyContentToIsolatedStorage("assets/newslist_154.txt");
            Common.CopyContentToIsolatedStorage("assets/newslist_155.txt");
            Common.CopyContentToIsolatedStorage("assets/newslist_156.txt");

            Common.CopyContentToIsolatedStorage("html/605.html");
            Common.CopyContentToIsolatedStorage("html/606.html");
            Common.CopyContentToIsolatedStorage("html/607.html");
            Common.CopyContentToIsolatedStorage("html/608.html");
            Common.CopyContentToIsolatedStorage("html/609.html");
            Common.CopyContentToIsolatedStorage("html/610.html");
            Common.CopyContentToIsolatedStorage("html/611.html");
            Common.CopyContentToIsolatedStorage("html/612.html");
            Common.CopyContentToIsolatedStorage("html/613.html");
            Common.CopyContentToIsolatedStorage("html/614.html");
            Common.CopyContentToIsolatedStorage("html/615.html");
            Common.CopyContentToIsolatedStorage("html/616.html");
            Common.CopyContentToIsolatedStorage("html/617.html");
            Common.CopyContentToIsolatedStorage("html/618.html");
            Common.CopyContentToIsolatedStorage("html/619.html");
            Common.CopyContentToIsolatedStorage("html/620.html");
            Common.CopyContentToIsolatedStorage("html/621.html");
            Common.CopyContentToIsolatedStorage("html/622.html");
            Common.CopyContentToIsolatedStorage("html/623.html");
            Common.CopyContentToIsolatedStorage("html/624.html");
            Common.CopyContentToIsolatedStorage("html/625.html");
            Common.CopyContentToIsolatedStorage("html/626.html");
            Common.CopyContentToIsolatedStorage("html/627.html");
            Common.CopyContentToIsolatedStorage("html/628.html");
            Common.CopyContentToIsolatedStorage("html/629.html");
            Common.CopyContentToIsolatedStorage("html/630.html");
            Common.CopyContentToIsolatedStorage("html/631.html");
            Common.CopyContentToIsolatedStorage("html/632.html");
            Common.CopyContentToIsolatedStorage("html/633.html");
            Common.CopyContentToIsolatedStorage("html/634.html");
            Common.CopyContentToIsolatedStorage("html/public.css");

            Common.CopyContentToIsolatedStorage("img/sec.png");
            Common.CopyContentToIsolatedStorage("img/20120421100400_2070700390.jpg");
            Common.CopyContentToIsolatedStorage("img/20120421100403_1140761310.jpg");
            Common.CopyContentToIsolatedStorage("img/20120421100407_1087758443.jpg");
            Common.CopyContentToIsolatedStorage("img/20120421100408_1954767082.jpg");
            Common.CopyContentToIsolatedStorage("img/20120421100409_2054110779.jpg");
            Common.CopyContentToIsolatedStorage("img/20120421100409_568606792.jpg");
            Common.CopyContentToIsolatedStorage("img/20120421100411_842408118.jpg");
            Common.CopyContentToIsolatedStorage("img/20120421100412_402381528.jpg");
            Common.CopyContentToIsolatedStorage("img/20120421100413_962641755.jpg");
            Common.CopyContentToIsolatedStorage("img/20120421100420_1164867353.jpg");
            Common.CopyContentToIsolatedStorage("img/20120421100427_850306642.jpg");
            Common.CopyContentToIsolatedStorage("img/20120421100434_352107047.jpg");
            Common.CopyContentToIsolatedStorage("img/20120421100443_175799942.jpg");
            Common.CopyContentToIsolatedStorage("img/20120421100443_517387200.jpg");
            Common.CopyContentToIsolatedStorage("img/20120421100444_711801407.jpg");
            Common.CopyContentToIsolatedStorage("img/20120421100458_216505623.jpg");
            Common.CopyContentToIsolatedStorage("img/20120421110412_1633587669.jpg");
            Common.CopyContentToIsolatedStorage("img/20120421110415_95131043.jpg");
            Common.CopyContentToIsolatedStorage("img/20120421110417_1817725040.jpg");
            Common.CopyContentToIsolatedStorage("img/20120421110418_507944689.jpg");
            Common.CopyContentToIsolatedStorage("img/20120421110424_1326724182.jpg");
            Common.CopyContentToIsolatedStorage("img/20120421110425_1086720711.jpg");
            Common.CopyContentToIsolatedStorage("img/20120421110433_951418213.jpg");
            Common.CopyContentToIsolatedStorage("img/20120421110436_906810777.jpg");
            Common.CopyContentToIsolatedStorage("img/20120421110437_1439969925.jpg");
            Common.CopyContentToIsolatedStorage("img/20120421110439_941316117.jpg");
            Common.CopyContentToIsolatedStorage("img/20120421110445_566867200.jpg");
            Common.CopyContentToIsolatedStorage("img/20120421110446_1015033563.jpg");
            Common.CopyContentToIsolatedStorage("img/20120421110450_464426416.jpg");
            Common.CopyContentToIsolatedStorage("img/20120421110459_937941203.jpg");

            #endregion
        }

        private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
        {
            string jsonClassList = "";
            using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
            {
                if (myIsolatedStorage.FileExists("assets/classlist.txt"))
                {
                    using (IsolatedStorageFileStream stream = myIsolatedStorage.OpenFile("assets/classlist.txt", FileMode.Open, FileAccess.Read))
                    {
                        if (stream.Length > 0)
                        {
                            using (StreamReader reader = new StreamReader(stream))
                            {
                                jsonClassList = reader.ReadLine();
                            }
                        }
                    }
                }
            }
            if (!String.IsNullOrEmpty(jsonClassList))
            {
                List<ClassList> listclass = JsonHelper.Deserialize<List<ClassList>>(jsonClassList);
                pList.ItemsSource = listclass;
            }
        }

        private void pList_Tap(object sender, GestureEventArgs e)
        {
            NavigationService.Navigate(new Uri(String.Format("/DetailList.xaml?c={0}", (pList.SelectedValue as ClassList).id), UriKind.Relative));
        }
    }
}